package com.example.smartcity1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity1.R;
import com.example.smartcity1.bean.ParklotOldListBean;

import java.util.List;


public class ParklotOldAdapter extends ArrayAdapter<ParklotOldListBean.RowsDTO> {


    public ParklotOldAdapter(@NonNull Context context, int resource, @NonNull List<ParklotOldListBean.RowsDTO> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_parkolt_old, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.plateNumberText = convertView.findViewById(R.id.plateNumber_text);
            viewHolder.monetaryText = convertView.findViewById(R.id.monetary_text);
            viewHolder.entryTimeText = convertView.findViewById(R.id.entryTime_text);
            viewHolder.outTimeText = convertView.findViewById(R.id.outTime_text);
            viewHolder.parkNameText = convertView.findViewById(R.id.parkName_text);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ParklotOldListBean.RowsDTO item = getItem(position);
        viewHolder.plateNumberText.setText(item.getPlateNumber());
        viewHolder.monetaryText.setText("收费金额: " + item.getMonetary() + "元");
        viewHolder.entryTimeText.setText("入场时间: " + item.getEntryTime());
        viewHolder.outTimeText.setText("出场时间: " + item.getOutTime());
        viewHolder.parkNameText.setText(item.getParkName());
        return convertView;
    }


    private class ViewHolder {
        TextView plateNumberText;
        TextView monetaryText;
        TextView entryTimeText;
        TextView outTimeText;
        TextView parkNameText;
    }
}
